import com.github.llyb120.calengine.entity.ScopeData

import static com.github.llyb120.performance.define.All.*;

quota {
    name "AVG"

    calculate { List list, String key ->
        def total = 0.0
        list.forEach(e -> {
            def item = e[key]
            if (item == null) {
                item = 0
            }
            total += item
        })
        return total / list.size()
    }

}

quota {
    name "variance"

    calculate { List list, String key ->
        def avg = AVG(list, key)
        list.forEach(e -> {
            def item = new BigDecimal(String.valueOf(e[key]))
            e["variance"] = (item - avg)**2
        })
        return list
    }
}


quota {
    name "test_jia_quan"
    calculate { ScopeData scopeData ->
        var total = 0
        scopeData.data.forEach(e -> {
            total += e.banka * 0.1
            total += e.xiaoka * 0.2
            total += e.daikuan * 0.3
            total += e.licai * 0.4
            total += e.baoxian * 0.5
        })
        return total
    }
}